import Vue from 'vue'

import Cookies from 'js-cookie'
import './styles/global.css'
import Element from 'element-ui'
// 拖拽弹窗，在需要用到拖拽功能的弹窗标签上加v-dialogDrag
import './utils/diretive.js'

import './assets/styles/element-variables.scss'

import '@/assets/fonts/iconfont.css'
import '@/assets/styles/reset.css'
import '@/assets/styles/flex.css' // 弹性布局
import '@/assets/styles/public.css'
import '@/assets/styles/index.scss' // global css
import '@/assets/styles/ruoyi.scss' // ruoyi css
import App from './App'
import store from './store'
import router from './router'
// import directive from './directive' // directive
import plugins from './plugins' // plugins

import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
Vue.use(VueQuillEditor)

import CryptoJS from 'crypto-js'
// 审批流
import 'babel-polyfill'
import './plugins/axios'
// import './plugins/element.js'
// import './css/override-element-ui.css'
import func from './plugins/preload.js'
import nodeWrap from '@/components/nodeWrap'

import { delTreeChildren } from '@/utils/util'
Vue.use(nodeWrap)
Vue.component('NodeWrap', nodeWrap) // 初始化组件

import followWorkShow from '@/components/nodeWrapShow'
Vue.use(followWorkShow)
Vue.component('FollowWorkShow', followWorkShow) // 初始化组件

import followWorkShowLinkNode from '@/components/nodeWrapShowLinkNode'
Vue.use(followWorkShowLinkNode)
Vue.component('FollowWorkShowLinkNode', followWorkShowLinkNode) // 关联节点信息的查看

import addNode from '@/components/addNode'
Vue.use(addNode)
Vue.component('AddNode', addNode) // 初始化组件
Vue.prototype.$func = func
Vue.config.productionTip = false
Vue.directive('enterNumber', {
  bind: function(el, { value = 2 }) {
    el = el.nodeName == 'INPUT' ? el : el.children[0]
    var RegStr = value == 0 ? `^[\\+\\-]?\\d+\\d{0,0}` : `^[\\+\\-]?\\d+\\.?\\d{0,${value}}`
    el.addEventListener('keyup', function() {
      el.value = el.value.match(new RegExp(RegStr, 'g'))
      el.dispatchEvent(new Event('input'))
    })
  }
})

import { download } from '@/utils/request'
import { openLoading, closeLoading } from '@/utils/loading'
import './assets/icons' // icon
import './permission' // permission control
import { getDicts } from '@/api/system/dict/data'
import { getConfigKey } from '@/api/system/config'
import {
  parseTime,
  resetForm,
  addDateRange,
  selectDictLabel,
  selectDictLabels,
  handleTree
} from '@/utils/ruoyi'
// 分页组件
import Pagination from '@/components/Pagination'
// 自定义表格工具组件
import RightToolbar from '@/components/RightToolbar'
// 富文本组件
import Editor from '@/components/Editor'
// 文件上传组件
import FileUpload from '@/components/FileUpload'
// 图片上传组件
import ImageUpload from '@/components/ImageUpload'
// 图片预览组件
import ImagePreview from '@/components/ImagePreview'
// 字典标签组件
import DictTag from '@/components/DictTag'
// 头部标签组件
import VueMeta from 'vue-meta'
// 字典数据组件
import DictData from '@/components/DictData'
// 树形图
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
// 全局方法挂载
Vue.prototype.getDicts = getDicts
Vue.prototype.getConfigKey = getConfigKey
Vue.prototype.parseTime = parseTime
Vue.prototype.resetForm = resetForm
Vue.prototype.addDateRange = addDateRange
Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.selectDictLabels = selectDictLabels
Vue.prototype.download = download
Vue.prototype.handleTree = handleTree
Vue.prototype.openLoading = openLoading
Vue.prototype.closeLoading = closeLoading
Vue.prototype.delTreeChildren = delTreeChildren
// 全局组件挂载
Vue.component('DictTag', DictTag)
Vue.component('Pagination', Pagination)
Vue.component('RightToolbar', RightToolbar)
Vue.component('Editor', Editor)
Vue.component('FileUpload', FileUpload)
Vue.component('ImageUpload', ImageUpload)
Vue.component('ImagePreview', ImagePreview)
Vue.component('Treeselect', Treeselect)
// Vue.use(directive)
Vue.use(plugins)
Vue.use(VueMeta)
DictData.install()

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */

Vue.use(Element, {
  size: Cookies.get('size') || 'medium' // set element-ui default size
})

Vue.config.productionTip = false
// element message二次封装
Vue.prototype.$vmNews = function(msg, type, duration = 3500) {
  this.$message({
    type: type || 'warning',
    message: msg,
    showClose: type != 'success',
    offset: 86,
    duration: type == 'success' ? 1000 : type == 'error' ? 5000 : duration
  })
}
Vue.prototype.$delConfirm = function(functionConcat) {
  return new Promise((resolve, reject) => {
    this.$confirm('确认删除该内容吗?', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      showClose: false,
      closeOnClickModal: false,
      closeOnPressEscape: false,
      type: 'warning'
    })
      .then(() => {
        resolve()
      })
      .catch(() => {
        // this.$vmNews("取消操作");
      })
  })
}
// type:error红色警告  warning提示   success成功  info小提示   canterSwitch是否开启取消按钮
Vue.prototype.$tipConfirm = function(message, type = 'warning', canterSwitch = false) {
  return new Promise((resolve, reject) => {
    this.$confirm(message, '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      showCancelButton: canterSwitch,
      showClose: false,
      closeOnClickModal: false,
      closeOnPressEscape: false,
      type: type
    })
      .then(() => {
        resolve()
      })
      .catch(() => {
        // reject()
        // this.$vmNews("取消操作");
      })
  })
}

new Vue({
  el: '#app',
  router,
  store,
  components: {
    nodeWrap, //* 审批新建页面
    followWorkShow, //* 审批查看页面
    followWorkShowLinkNode, //* 关联节点信息的查看
    addNode
  },
  render: (h) => h(App)
})
